package com.bky.service.impl;

import com.bky.aop.Constants;
import com.bky.aop.SystemServiceLog;
import com.bky.dao.AddMapper;
import com.bky.model.Add;
import com.bky.service.AddService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by shipeilei on 2017/10/17.
 */
@Service
public class AddServiceImpl extends BaseServiceImpl implements AddService{

    @SystemServiceLog(description = Constants.INSERT, tableName = Constants.TADD)
    @Override
    public String addInfo(Add addInfo) {
        if (this.getWriteMapper(AddMapper.class).insertSelective(addInfo) == 1) {
            return "添加成功";
        }
        return "添加失败";
    }

    @Override
    public List<Add> getAll() throws Exception {
        System.out.println("main 当前线程名称：" + Thread.currentThread().getName());
        return getWriteMapper(AddMapper.class).getAll();
    }
    @SystemServiceLog(description = Constants.DELETE, tableName = Constants.TADD)
    @Override
    public String delete(Integer id) {
        if (this.getWriteMapper(AddMapper.class).deleteByPrimaryKey(id) == 1) {
            return "删除成功";
        }
        return "删除失败";
    }

    @Override
    public Add findById(Integer id) {
        return this.getWriteMapper(AddMapper.class).selectByPrimaryKey(id);
    }
    @SystemServiceLog(description = Constants.UPDATE, tableName = Constants.TADD)
    @Override
    public String update(Add addInfo) {
        if (this.getWriteMapper(AddMapper.class).updateByPrimaryKeySelective(addInfo) == 1) {
            return "更新成功";
        }
        return "更新失败";
    }
}
